home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / finnslator / finnslator.asm next >
Assembly Source File  |  1980-01-03  |  7KB  |  275 lines

  1. ;+asm
  2. ;do
  3. ;*
  4. ;
  5. ; ### Finnslator.library by JM v 1.4 ###
  6. ;
  7. ; - Created 901024 by JM -
  8. ;
  9. ;
  10. ; Bugs: Doesn't split the input string at word boundary on buffer full
  11. ;       conditions.
  12. ;
  13. ;
  14. ; Edited:
  15. ;
  16. ; - 901024 by JM -> v0.01    - basics written (see sample.library.asm).
  17. ; - 901025 by JM -> v1.00    - it works now.  lots of room for
  18. ;                  improvements, though.
  19. ; - 901026 by JM -> v1.1    - now special commands are processed
  20. ;                  before alphabets.
  21. ; - 901029 by JM -> v1.2    - destination buffer full condition now
  22. ;                  detected.
  23. ;                - ` now acts as an escape character.
  24. ;                - returns error code in d0.
  25. ; - 901029 by JM -> v1.3    - compatibility with original Translate()
  26. ;                  improved.
  27. ; - 901029 by JM -> v1.4    - still some fixes.  de-alping.
  28. ;
  29. ;
  30.  
  31. VERSION    EQU    1
  32. REVISION    EQU    4
  33.  
  34. SPEC        macro    * <orig_char>,<dest_string>
  35.         dc.b    SPEC2\@-SPEC1\@
  36.         dc.b    \1
  37. SPEC1\@        dc.b    \2
  38. SPEC2\@
  39.         endm
  40.  
  41.         include    "exec/types.i"
  42.         include    "exec/initializers.i"
  43.         include    "exec/libraries.i"
  44.         include    "exec/lists.i"
  45.         include    "exec/alerts.i"
  46.         include    "exec/resident.i"
  47.         include    "libraries/dos.i"
  48.  
  49.         include    "finnslatorbase.i"
  50.  
  51. begin        moveq    #-1,d0            ; if somebody runs us...
  52.         rts
  53.  
  54. ROMTag        dc.w    RTC_MATCHWORD        ; UWORD RT_MATCHWORD
  55.         dc.l    ROMTag            ; APTR  RT_MATCHTAG
  56.         dc.l    EndOfLib        ; APTR  RT_ENDSKIP
  57.         dc.b    RTF_AUTOINIT        ; UBYTE RT_FLAGS
  58.         dc.b    VERSION            ; UBYTE RT_VERSION
  59.         dc.b    NT_LIBRARY        ; UBYTE RT_TYPE
  60.         dc.b    0            ; BYTE  RT_PRI
  61.         dc.l    LibName            ; APTR  RT_NAME
  62.         dc.l    LibId            ; APTR  RT_IDSTRING
  63.         dc.l    InitStuff        ; APTR  RT_INIT
  64.  
  65. LibName        FINNSLATORNAME
  66. LibId        dc.b    'finnslator 1.4 (29 Oct 1990)',13,10,0
  67.         ds.w    0
  68.  
  69. InitStuff    dc.l    FinnslatorBase_SIZEOF    ; size of library base
  70.         dc.l    Functions        ; pointer to function table
  71.         dc.l    LibBaseData        ; pointer to lib base data
  72.         dc.l    InitRoutine        ; ptr to initializing routine
  73.  
  74. Functions    dc.l    r_Open            ; library Open call
  75.         dc.l    r_Close            ; library Close call
  76.         dc.l    r_Expunge        ; library Expunge call
  77.         dc.l    r_Null            ; reserved for Exec
  78.         dc.l    r_Translate        ; Translate call
  79.         dc.l    -1            ; end marker
  80.  
  81. LibBaseData    INITBYTE    LN_TYPE,NT_LIBRARY
  82.         INITLONG    LN_NAME,LibName
  83.         INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  84.         INITWORD    LIB_VERSION,VERSION
  85.         INITWORD    LIB_REVISION,REVISION
  86.         INITLONG    LIB_IDSTRING,LibId
  87.         dc.l        0
  88.  
  89. InitRoutine    move.l    a5,-(sp)        ; save a5
  90.         move.l    d0,a5            ; library base into a5
  91.         move.l    a6,finsb_SysLib(a5)    ; save ExecBase into LibBase
  92.         move.l    a0,finsb_SegList(a5)    ; save SegList pointer
  93.  
  94. ; additional initializing would be done here
  95.  
  96.         move.l    a5,d0            ; lib base back to d0
  97.         move.l    (sp)+,a5        ; restore a5
  98.         rts
  99.  
  100. r_Open        addq.w    #1,LIB_OPENCNT(a6)    ; one more user
  101.         bclr    #LIBB_DELEXP,finsb_Flags(a6) ; so expunge impossible
  102.         move.l    a6,d0            ; return library base in d0
  103.         rts
  104.  
  105. r_Close        moveq    #0,d0            ; return value
  106.         subq.w    #1,LIB_OPENCNT(a6)    ; one user less
  107.         bne.s    1$            ; last user?
  108.         btst    #LIBB_DELEXP,finsb_Flags(a6) ; delayed Expunge?
  109.         beq.s    1$
  110.         bsr    r_Expunge        ; yes, do it
  111. 1$        rts    ; if other users, just return
  112.  
  113. r_Expunge    movem.l    d2/a5-a6,-(sp)
  114.         move.l    a6,a5            ; library base pointer
  115.         move.l    finsb_SysLib(a5),a6    ; ExecBase
  116.         tst.w    LIB_OPENCNT(a5)        ; are we still open?
  117.         beq.s    1$
  118.         bset    #LIBB_DELEXP,finsb_Flags(a5) ; yes, delayed Expunge
  119.         moveq    #0,d0            ; and return a zero
  120.         movem.l    (sp)+,d2/a5-a6
  121.         rts
  122. 1$        move.l    finsb_SegList(a5),d2    ; SegList* to d2
  123.         move.l    a5,a1
  124.         xref    _LVORemove        ; remove from library list
  125.         jsr    _LVORemove(a6)
  126.  
  127. ; other cleanup operations would be done here
  128.  
  129.         moveq    #0,d0
  130.         move.l    a5,a1            ; library base
  131.         move.w    LIB_NEGSIZE(a5),d0    ; get size below the base
  132.         sub.l    d0,a1            ; get pointer to mem block
  133.         add.w    LIB_POSSIZE(a5),d0    ; add size after the base
  134.         xref    _LVOFreeMem        ; free memory used by lib
  135.         jsr    _LVOFreeMem(a6)
  136.         move.l    d2,d0            ; return SegList pointer
  137.         movem.l    (sp)+,d2/a5-a6
  138.         rts
  139.  
  140. r_Null        moveq    #0,d0            ; Exec reserved routine
  141.         rts
  142.  
  143. ******* Actual library routine(s) begin here: *******
  144.  
  145. ; error = Translate(input,length,output,bufsiz);
  146. ;
  147. ; inputs:
  148. ;    a0 = input string (may be NULL terminated)
  149. ;    d0 = length of input string
  150. ;    a1 = output buffer
  151. ;    d1 = size of output buffer
  152. ; internal variables:
  153. ;    a0 = source pointer
  154. ;    a1 = destination pointer
  155. ;    d0 = characters left in source buffer
  156. ;    d1 = number of free bytes in destination buffer
  157. ;    d2 = temporary (character being processed)
  158. ;    d3 = temporary for table search
  159. ;    d4 = storage for input length
  160. ; outputs:
  161. ;    d0 = NULL (no error) or -N where N is index to first char in input
  162. ;         buffer that was not processed
  163. ;            
  164.  
  165. r_Translate    movem.l    d2-d4/a2,-(sp)
  166.         move.l    d0,d4        ; length of input string
  167.         subq.l    #1,d1        ; space for NULL char
  168.         ble.s    exitnow        ; no space in buffer at all
  169.         bra.s    loop
  170. reploop        subq.l    #1,d0        ; one char less
  171. loop        tst.l    d0        ; characters left?
  172.         beq.s    endofit        ; none -> exit
  173.         moveq    #0,d2        ; clear d2
  174.         move.b    (a0)+,d2    ; get one char
  175.         beq.s    endofit        ; NULL -> exit
  176.  
  177.         cmp.b    #96,d2        ; is it a ` ?
  178.         bne.s    10$
  179.         subq.l    #1,d1
  180.         bmi.s    endofit        ; end of destination buffer
  181.         subq.l    #1,d0
  182.         beq.s    endofit        ; end of source string
  183.         move.b    (a0)+,(a1)+    ; copy one char literally
  184.         bra.s    reploop
  185.  
  186. 10$        cmp.b    #'a',d2        ; convert to UPPER CASE
  187.         bcs.s    1$
  188.         cmp.b    #'z',d2
  189.         bhi.s    1$
  190.         sub.b    #32,d2
  191. 1$        cmp.b    #224,d2        ; convert special chars also
  192.         bcs.s    2$
  193.         sub.b    #32,d2
  194. 2$        bsr    dospecials
  195.         tst.l    d1
  196.         bmi.s    endofit
  197.         cmp.b    #'A',d2        ; is it an alphabet?
  198.         bcs.s    reploop
  199.         cmp.b    #'Z',d2
  200.         bhi.s    reploop
  201.         sub.b    #'A',d2        ; yes -> A->0; Z->25
  202.         lea    alphatable(pc),a2 ; convert into phonemes
  203.         add.w    d2,a2
  204.         add.w    d2,a2        ; address in table
  205.         subq.l    #1,d1
  206.         bmi.s    endofit        ; destination buffer overflow
  207.         move.b    (a2)+,d2    ; get 1 or 2 bytes from table
  208.         beq.s    100$
  209.         subq.l    #1,d1
  210.         bmi.s    endofit        ; destination buffer overflow
  211.         move.b    d2,(a1)+
  212. 100$        move.b    (a2)+,(a1)+    ; copy bytes into buffer
  213.         subq.l    #1,d0        ; one char processed
  214.         bra.s    loop
  215. endofit        clr.b    (a1)        ; NULL terminate string
  216. exitnow        tst.l    d0
  217.         beq.s    101$
  218.         sub.l    d4,d0        ; -(idx to next char) or NULL
  219. 101$        movem.l    (sp)+,d2-d4/a2
  220.         rts
  221.  
  222. dospecials    lea    othertable(pc),a2
  223.         moveq    #0,d3
  224. dospecloop    add.w    d3,a2        ; skip to next entry
  225.         move.b    (a2)+,d3    ; get size of entry
  226.         beq.s    dosendeth    ; NULL = end of table
  227.         cmp.b    (a2)+,d2    ; compare with this entry
  228.         bne.s    dospecloop    ; if not equal, try next
  229.         sub.l    d3,d1        ; right entry found:
  230.         bge.s    dospecbufok    ; enough room in buffer?
  231.         moveq    #-1,d1        ; nope -> d1=-1; return
  232.         rts
  233. dospeccopy    move.b    (a2)+,(a1)+    ; copy string
  234. dospecbufok    dbf    d3,dospeccopy
  235.         moveq    #0,d2        ; return NULL
  236. dosendeth    rts
  237.  
  238. alphatable    dc.w    'AH','B','S','D','EH','F','G'
  239.         dc.w    '/H','IH','Y','K','L','M','N'
  240.         dc.w    'OH','P','KV','R','S','T','UH'
  241.         dc.w    'V','W','KS','IX','TS'
  242.  
  243. othertable    SPEC    32,32    ; SPC
  244.         SPEC    13,32    ; CR -> SPC
  245.         SPEC    '.','.'
  246.         SPEC    44,44    ; ,
  247.         SPEC    '?','?'
  248.         SPEC    '(','('
  249.         SPEC    ')',')'
  250.         SPEC    '-','-'
  251.         SPEC    'I','IHIH'    ; I
  252.         SPEC    196,'AE'
  253.         SPEC    214,'ER'
  254.         SPEC    197,'OH'
  255.         SPEC    209,'NX'    ; äng
  256.         SPEC    182,'PIHIHIHIHAH'
  257.         SPEC    '*','TAE/HTIH'
  258.         SPEC    '0','NOHLLAH'
  259.         SPEC    '1','IXKSIH'
  260.         SPEC    '2','KAHKSIH'
  261.         SPEC    '3','KOHLMEH'
  262.         SPEC    '4','NEHLYAE'
  263.         SPEC    '5','VIHIHIHIHSIH'
  264.         SPEC    '6','KUHUHSIH'
  265.         SPEC    '7','SEHIHTSEHMAEN'
  266.         SPEC    '8','KAH/HDEHKSAHN'
  267.         SPEC    '9','IXIX/HDEHKSAEN'
  268.         dc.b    0
  269.         ds.w    0
  270.  
  271. ***********************************************************************
  272.  
  273. EndOfLib    end
  274.  
  275.